#coding:utf8

import pdb
pdb.set_trace()
import time

from socket import AF_INET,SOCK_STREAM,socket
from thread import start_new
import struct
HOST='localhost'	# 服务器地址
PORT=1000		# 服务器端口
BUFSIZE=1024
ADDR=(HOST , PORT)
client = socket(AF_INET,SOCK_STREAM)	# 创建socket, TCP
client.connect(ADDR)			# 连接服务器

def sendData(sendstr,commandId):
    HEAD_0 = chr(0)	# 协议头0
    HEAD_1 = chr(0)	# 协议头1
    HEAD_2 = chr(0)	# 协议头2
    HEAD_3 = chr(0)	# 协议头3
    ProtoVersion = chr(0)	# 协议头版本号
    ServerVersion = 0	# 服务器版本号
    sendstr = sendstr
    data = struct.pack('!sssss3I',HEAD_0,HEAD_1,HEAD_2,\
                       HEAD_3,ProtoVersion,ServerVersion,\
                       len(sendstr)+4,commandId)
    senddata = data+sendstr
    return senddata

def resolveRecvdata(data):
    head = struct.unpack('!sssss3I',data[:17])
    length = head[6]
    data = data[17:17+length]
    return data

s1 = time.time()

def start():
    for i in xrange(10):
        client.sendall(sendData('Hello Server! I am Client.',1))	# 发送数据给服务器

for i in range(10):
    start_new(start,())
while True:
    pass

